//
//  ViewController.swift
//  test_swift
//
//  Created by fangyuan ding on 2021/5/31.
//

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // 数字数组转换为字符串数组
//        print([1, 2, 3].map{"\($0)"})
//        print([1, 2, 3].filter{$0 % 2 == 0} )// 筛选偶数
//        print([1, 2, 3].reduce(""){$0 + "\($1)"})// 转换为字符串并拼接
//       //flatMap
//        let array = [1,2,5,6,7,nil]
//        let array_map = array.map { $0 }
//        //[Optional(1), Optional(2), Optional(5), Optional(6), Optional(7), nil]
//        let array_flatmap = array_map.flatMap { $0 }
//        print(array_flatmap)
        //[1, 2, 5, 6, 7]
        
//        let array = [["1", "2"],["3", "4"]]
//        let array_map = array.map { $0 }
//        //[["1", "2"], ["3", "4"]]
//        let array_flatmap = array_map.flatMap { $0 }
//        print(array_flatmap)
        //["1", "2", "3", "4"]
//        var arr = ["123","test","jcak","-30"]
//        var arr2 = arr.map{ Int($0)}
//        print(arr2)
//        var arr3 = arr.compactMap{Int($0)}
//        print(arr3)
        var arr = [1,2,3,4]
        print(arr.map{$0 * 2})
        print(arr.reduce([]) {$0 + [$1 * 2]})
        print(arr.filter{$0 % 2 == 0})
        print(arr.reduce([]){$1 % 2 == 0 ? $0 + [$1] : $0})
    }
    
   

}

